import { defineStore } from 'pinia'
import request from '../utils/request'
import { IChannelItem, IResponse } from '../types/data'

export default defineStore('channel', {
  state: () => ({
    channelList: [] as IChannelItem[],
  }),
  actions: {
    // #1 准备获取频道的 action
    async getChannelList() {
      // get 的第一个泛型参数规定的就是 r.data 的类型
      // const r = await request.get<{ data: { channels: { id: number; name: string }[] }; message: string }>('/channels')
      const r = await request.get<IResponse<{ channels: IChannelItem[] }>>('/channels')
      this.channelList = r.data.data.channels
    },
  },
  getters: {},
})
